#include <stdio.h>

bool is31(int month)
{
    return (month==1||month==3||month==5||month==7||month==8||month==10||month==12);
}

bool isrun(int year)
{
    if(year%400==0)
        return true;
    if(year%4==0&&year%100!=0)
        return true;
    return false;
}

void nextMonth(int &month,int &day)
{
    month++;
    day=1;
}

int main()
{
    int year,month,day;

    while(1)
    {
        scanf("%d %d %d",&year,&month,&day);
        day++;

        if(day==32)
            nextMonth(month,day);
        else
        {
            if(day==31&&!is31(month))
                nextMonth(month,day);
            {
                if(month==2)
                {
                    if(day==29&&(!isrun(year)))
                        nextMonth(month,day);
                    else
                    {
                        if(day==30&&isrun(year))
                            nextMonth(month,day);
                    }
                }
            }
        }

        if(month==13)
        {
            month=1;
            year++;
        }

        printf("%d %d %d\n",year,month,day);
    }
}
